<?php
class Application_Model_Group {
	protected $_id;

	public function id() {
		return $this->_id;
	}

	public function set_id($id) {
		$this->_id = $id;
	}

	protected $_name;

	public function name() {
		return $this->_name;
	}

	public function set_name($name) {
		$this->_name = $name;
	}

	protected $_categorizing;

	public function categorizing() {
		return $this->_categorizing;
	}

	public function set_categorizing($categorizing) {
		$this->_categorizing = $categorizing;
	}

	protected $_image_id;

	public function image_id() {
		return $this->_image_id;
	}

	public function set_image_id($image_id) {
		$this->_image_id = $image_id;
	}

	protected $_description;

	public function description() {
		return $this->_description;
	}

	public function set_description($description) {
		$this->_description = $description;
	}

	protected $_owner_id;

	public function owner_id() {
		return $this->_owner_id;
	}

	public function set_owner_id($owner_id) {
		$this->_owner_id = $owner_id;
	}

    public function can_delete(Application_Model_User $user) {
        return (($user->id() == $this->owner_id()) ||
                (!$this->categorizing() && $user->isAdmin()) ||
                ($this->categorizing() && $user->isSuperAdmin()));
    }

    protected $_image_uri;

	function __construct($id,$name,$categorizing,$image_id,$description,$owner_id) {
		$this->_id = $id;
		$this->_name = $name;
		$this->_categorizing = $categorizing;
		$this->_image_id = $image_id;
		$this->_description = $description;
		$this->_owner_id = $owner_id;
        $this->_image_uri = null;
	}

    public function get_image_uri() {
        if (!$this->_image_uri) {
            if ($this->_image_id == null) {
                $this->_image_uri = '/images/dflt_group.jpg';
            } else {
                $imgmapper = new Application_Model_ImageMapper();
                $this->_image_uri = $imgmapper->find($this->_image_id)->uri();
            }
        }
        return $this->_image_uri;
    }
}
